 
use "$path\datasets\rd_dataset.dta", clear
keep if in_rdd_sample==1



gen close_female=(margin_1<=0.05 & margin_1>=0) if margin_1<.
gen close_male=(margin_1>=-0.05 & margin_1<0) if margin_1<.
gen non_close_female=(margin_1>0.05 & margin_1<.) if margin_1<.
gen non_close_male=(margin_1<-0.05) if margin_1<.




 
ivreg log_bevoelkerung close_male close_female  non_close_female , r cluster(gkz)
est store m1
sum log_bevoelkerung if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)

ivreg sum_elected_hcd  close_male close_female  non_close_female, r cluster(gkz)
est store m2
sum sum_elected_hcd if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg total_child_places_pc close_male close_female  non_close_female , r cluster(gkz)
est store m3
sum total_child_places_pc if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)




ivreg log_bevoelkerung margin_1 , r cluster(gkz)
est store m4
sum log_bevoelkerung if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)



ivreg sum_elected_hcd  margin_1, r cluster(gkz)
est store m5
sum sum_elected_hcd if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)


ivreg total_child_places_pc margin_1 , r cluster(gkz)
est store m6
sum total_child_places_pc if e(sample)
estadd scalar  mean_depvar =r(mean)
estadd scalar sd_depvar =r(sd)










esttab  m1 m2 m3 m4 m5 m6 using TableA26/table26.txt, replace order( ) mlabel(,none) ///
cells(b(label(coef.) star fmt(%8.3f) ) se(label((z)) par fmt(%6.3f))) ///
collabels(none) ///
  keep (close_male close_female  non_close_female margin_1  ) ///
  stats( N   N_clust mean_depvar sd_depvar , layout( @  @  `""@ (@)""' )  fmt(  %9.0g %9.0g  %9.2f %9.2f  ) ///
 labels(  "N"  "Municipalities" "Mean (SD)"  )) ///
starlevels(* 0.10 ** 0.05 *** 0.01) ///
  indicate( ) style(tab) ///
varlabels(  close_male "Close male winner" close_female  "Close female winner" non_close_female "Non-close female winner" margin_1 "Margin of victory of female candidate")  ///


************************************************************************************************************************************


